home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 106_01.zip / UTIL1.C < prev    next >
Text File  |  1993-06-26  |  2KB  |  118 lines

  1. /*
  2.         Function Summary
  3.         ----------------
  4.  
  5. charcnt(bufpntr)
  6.  
  7.     returns the number of characters in the file at bufpntr.
  8.     file must be in a continuous block of RAM.
  9.  
  10. linecnt(bufpntr)
  11.  
  12.     returns the number of lines in the file at bufpntr.
  13.     file must be in a continuous block of RAM.
  14.  
  15. ntoi(number,base)
  16.  
  17.     converts ASCII digits to an integer using any base
  18.     except split octal (see otoi). white space may preceed
  19.     the ASCII string which must end with '\0' after the
  20.     final digit.
  21.  
  22. otoi(number)
  23.  
  24.     converts ASCII digits representing a split octal
  25.     number in the format xxx.xxx{a} to an integer. white
  26.     space may preceed the ASCII string which must be
  27.     7 characters long (3 chars,'.',3 chars). any following
  28.     characters are ignored (ie. does not require '\0' as
  29.     final delimiter).
  30.  
  31. wordcnt(bufpntr)
  32.  
  33.     returns the number of words in the file at bufpntr.
  34.     file must be in a continuous block of RAM. note that
  35.     '\n' is handled explicitly as CRLF to avoid false
  36.     triggering of the word count on an empty line.
  37. */
  38.  
  39. #define    LF    10
  40. #define    CR    13
  41. #define    EOF    26
  42. #define    NO    0
  43. #define    YES    -1
  44.  
  45. charcnt(bufpntr)
  46. char *bufpntr;
  47. {
  48.     int nc;
  49.     char c;
  50.  
  51.     nc = 0;
  52.     while((c = *bufpntr++) != EOF) nc += 1;
  53.     return nc;
  54. }
  55.  
  56. linecnt(bufpntr)
  57. char *bufpntr;
  58. {
  59.     int nc;
  60.     char c;
  61.  
  62.     nc = 0;
  63.     while((c = *bufpntr++) != EOF) {
  64.        if (c == '\n') nc += 1;
  65.     }
  66.     return nc;
  67. }
  68.  
  69. ntoi(n,b)
  70. char *n;
  71. int b;
  72. {
  73.     int val,sign;
  74.     char c;
  75.  
  76.     val=0; sign=1;
  77.     while ((c = *n) == '\t' || c == ' ') ++n;
  78.     if (c == '-') {sign = -1; n++;}
  79.     while (dig(c = *n++)) {
  80.        if (b == 16 && c >= 'A' && c <= 'F') c -= 7;
  81.        val = val * b + c - '0';
  82.     }
  83.     return sign*val;
  84. }
  85.  
  86. otoi(n)
  87. char *n;
  88. {
  89.     int val, b, i;
  90.     char c;
  91.  
  92.     val = 0; b = 16384;
  93.  
  94.     while ((c = *n) == '\t' || c == ' ') ++n;
  95.     for (i = 0; i < 7; i++) {
  96.        if ((c = *n) == '.') {++n; b = 64;}
  97.        else {c = *n++; val = val + (b * (c - '0')); b /= 8;}
  98.     }
  99.     return val;
  100. }
  101.  
  102. wordcnt(bufpntr)
  103. char *bufpntr;
  104. {
  105.     int inword, wc;
  106.     char c;
  107.  
  108.     wc = 0; inword = NO;
  109.     while((c = *bufpntr++) != EOF) {
  110.        if (c == ' ' || c == CR || c == '\t') inword = NO;
  111.        else if ((inword == NO) && (c != LF)) {
  112.           inword = YES; wc += 1;
  113.        }
  114.     }
  115.     return wc;
  116. }
  117.  
  118.